package com.example.mydefinedview1.base
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.example.mydefinedview1.extension.getViewBinding

/**
 *
 * @Author： LJH
 * @Time： 2022/6/23
 * @description：
 */
abstract class BaseFragment<VB:ViewDataBinding>:Fragment(), BaseBinding<VB> {
    protected lateinit var mBinding:VB
        private set
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mBinding = getViewBinding(inflater,container)
        return mBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        mBinding.initBinding()
    }

    override fun onDestroy() {
        super.onDestroy()
        //此处记得取消绑定，避免内存泄露
        if (::mBinding.isInitialized) {
            mBinding.unbind()
        }
    }
}